package cn.edu.zut.internship.web.controller.report;

import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.bean.sys.SysUser;
import cn.edu.zut.internship.iservice.report.ReportSV;
import cn.edu.zut.internship.web.utils.UserInfoUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
@RestController
@RequestMapping("/report")
public class ReportController {
    @Reference
    ReportSV reportSV;

    /**
     * 报告列表查看
     * @param params
     * @return
     */
    @RequestMapping("/getReportList")
    public Result getReportList(@RequestBody Map params) {
        Result result = new Result();
        result = reportSV.selectReport(params);
        return result;
    }
    /**
     * 学生账号我的报告列表查看
     * @param params
     * @return
     */
    @RequestMapping("/getMyReportList")
    public Result getMyReportList(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String teachAccount = userInfo.getUserAccount();
        params.put("studentAccount",teachAccount);
        result = reportSV.selectReport(params);
        return result;
    }
    /**
     * 教师查询待审核报告列表
     */
    @RequestMapping("/getVerifyReport")
    public Result getVerifyReport(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String teachAccount = userInfo.getUserAccount();
        params.put("teachAccount",teachAccount);
        result = reportSV.getVerifyReport(params);
        return result;
    }
    /**
     * 查询报告详情
     * @param params
     * @return
     */
    @RequestMapping("/getReport")
    public Result getReport(@RequestBody Map params) {
        Result result = new Result();
//        Long reportId = Long.valueOf((String) params.get("reportId"));
        result = reportSV.getReportById((Long) params.get("reportId"));
        return result;
    }

    /**
     * 新增报告
     * @param params
     * @return
     */
    @RequestMapping("/addReport")
    public Result addReport(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("studentAccount",userInfo.getUserAccount());
        result = reportSV.addReport(params);
        return result;
    }

    /**
     * 更新报告
     * @param params
     * @return
     */
    @RequestMapping("/updateReport")
    public Result updateReport(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("updateAccount",userInfo.getUserAccount());
        result = reportSV.updateReport(params);
        return result;
    }

    /**
     * 删除报告
     * @param params
     * @return
     */
    @RequestMapping("/deleteReport")
    public Result deleteReport(@RequestBody Map params) {
        Result result = new Result();
        Long reportId = Long.valueOf((String)params.get("reportId"));
        result = reportSV.delectReport(reportId);
        return result;
    }


    /**
     * 教师驳回报告
     * @param params
     * @return
     */
    @RequestMapping("/rejectReport")
    public Result rejectReport(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("updateAccount",userInfo.getUserAccount());
        result = reportSV.rejectReport(params);
        return result;
    }
    /**
     * 获取学生实训报告完成情况
     * @param params
     * @return
     */
    @RequestMapping("/getReportProgress")
    public Result getReportProgress(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("updateAccount",userInfo.getUserAccount());
        result = reportSV.getReportProgress(params);
        return result;
    }

    /**
     * 获取学生报告已提交数和总需提交数
     * @param params
     * @return
     */
    @RequestMapping("/getMyReportNum")
    public Result getMyReportNum(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("studentAccount",userInfo.getUserAccount());
        result = reportSV.getMyReportNum(params);
        return result;
    }

    /**
     * 提醒教师审理报告
     * @param params
     * @return
     */
    @RequestMapping("/remindVerifyReport")
    public Result remindVerifyReport(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("userInfo",userInfo);
        result = reportSV.remindVerifyReport(params);
        return result;
    }
}
